<?php

namespace app\controller\web;

use app\exception\ErrnoPlus;
use app\service\CountryCodeService;
use app\validate\CountryCodeValidate;

use app\validate\PageValidate;
use share\exception\ApiException;
use share\utils\Helper;

class CountryCodeController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new CountryCodeValidate();
    }

    /**
     * 新增视频教程
     */
    public function add_action(){
        $input = $this->check();
        $data = CountryCodeService::addCountryCode($input);
        return self::ok($data);
    }

    /**
     * 修改视频教程
     */
    public function edit_action(){
        $input = $this->check();
        $data = CountryCodeService::updateCountryCode($input);
        return self::ok($data);
    }

    /**
     * 删除视频教程
     */
    public function del_action(){
        $input = $this->check();
        $data = CountryCodeService::delCountryCode($input['isocode']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){        
        $page = $this->check('pageInfo',null,(new PageValidate()));
        $input = $this->check();       
        $data = CountryCodeService::getListInfo($input,$page);
        $data = Helper::arrayListReplaceKey($data,[
            'phone_code' => 'phoneCode',
            'location_name'=> 'locationName',
            'create_time' => 'createTime',
            'update_time' => 'updateTime',
        ]);
        $total = CountryCodeService::getListCountInfo($input);
        return self::ok(self::formatPageData($page,$total,$data));
    }

}